
**# Import data
cd "/Users/TJRyan/Library/CloudStorage/Dropbox/2022 Primary Survey/Personal funds experiment/Replication files"

use "rawdata.dta"

**# Variable names
rename totalmoney cand1_money
rename tjrwinperc_1 electability_1
rename tjrwinperc_2 electability_2
rename tjrwinner winner

**# Partisanship
gen pidr2 = .
replace pidr2 = 1 if pid=="Democrat" & regexm(pidstrong, "Strong")==1 // Strong case sensitive
replace pidr2 = 2 if pid=="Democrat" & regexm(pidstrong, "Not")==1 
replace pidr2 = 3 if pid=="Independent" & regexm(pidlean, "Democrat")==1 
replace pidr2 = 4 if pid=="Independent" & regexm(pidlean, "Neither")==1 
replace pidr2 = 5 if pid=="Independent" & regexm(pidlean, "Republican")==1 
replace pidr2 = 3 if pid=="Don't know/other" & regexm(pidlean, "Democrat")==1 
replace pidr2 = 4 if pid=="Don't know/other" & regexm(pidlean, "Neither")==1 
replace pidr2 = 5 if pid=="Don't know/other" & regexm(pidlean, "Republican")==1 
replace pidr2 = 6 if pid=="Republican" & regexm(pidstrong, "Not")==1 
replace pidr2 = 7 if pid=="Republican" & regexm(pidstrong, "Strong")==1 

lab def pidr2 1 "Strong Democrat" 4 "Pure independent" 7 "Strong Republican"
lab val pidr2 pidr2

recode pidr2 (1 2 3 = 1) (4 = 3) (5 6 7 = 2), gen(pid3)
lab def pid3 1 "Democrat" 2 "Republican" 3 "Pure independent"
lab val pid3 pid3

recode pidr2 (1 2 = 1) (3 4 5 = 3) (6 7 = 2), gen(pid3_alt)
lab val pid3_alt pid3

**# Primary voters
gen primaryvoter = 0
replace primaryvoter = 1 if regexm(participation, "primary")==1

gen primary_regular = .
replace primary_regular = 1 if primaryfreq=="Always"
replace primary_regular = 1 if primaryfreq=="Nearly always"
replace primary_regular = 0 if primaryfreq=="Never"
replace primary_regular = 0 if primaryfreq=="Rarely"
replace primary_regular = 0 if primaryfreq=="Sometimes"

**# Dependent variables
gen electability_skip = 1 if electability_1==. | electability_2==.
egen electability_response = rowmax(electability_1 electability_2)
replace electability_1 = 50 if electability_1==. & electability_response!=. // answered one electability question, but left electability1 slider at 50.
replace electability_2 = 50 if electability_2==. & electability_response!=. // answered one electability question, but left electability2 slider at 50.

gen electability_dif = electability_1 - electability_2 // DV

**# Money
gen cand1_grassroots = cand1_money - personalmoney

gen percent_self = personalmoney / cand1_money // 

**# Demographics

* Race
encode race, gen(raceenc)
gen race_cat = .
replace race_cat = 1 if raceenc==15
replace race_cat = 2 if raceenc==3
replace race_cat = 3 if raceenc==2
replace race_cat = 4 if raceenc==8
replace race_cat = 5 if raceenc==1
replace race_cat = 7 if raceenc==14
replace race_cat = 8 if raceenc==13
replace race_cat = 6 if race_cat==. & race!=""

lab def race_cat 1 "White only" 2 "Black only" 3 "Asian only" 4 "Hispanic only" 5 "American Indian…" 6 "Multiracial" 7 "other" 8 "Native Hawaiian or Pac Islander"
lab val race_cat race_cat

tab race_cat, m

* Gender
tab female, m
encode female, gen(gender)

* Age
tab age, m
encode age, gen(age2)

* Education
tab edu
gen edu2 = .
replace edu2 = 1 if edu == "Did not attend high school"
replace edu2 = 2 if edu == "Some high school, did not graduate"
replace edu2 = 3 if edu == "High school graduate"
replace edu2 = 4 if edu == "Some college"
replace edu2 = 5 if edu == "Associate's Degree"
replace edu2 = 6 if edu == "Bachelor's Degree"
replace edu2 = 7 if edu == "Master's Degree"
replace edu2 = 8 if edu == "Professional Degree (e.g. JD, MD)"
replace edu2 = 9 if edu == "Doctorate"

label define edu2 ///
    1 "Did not attend high school" ///
    2 "Some high school, did not graduate" ///
    3 "High school graduate" ///
    4 "Some college" ///
    5 "Associate's Degree" ///
    6 "Bachelor's Degree" ///
    7 "Master's Degree" ///
    8 "Professional Degree (e.g. JD, MD)" ///
    9 "Doctorate"
	
lab val edu2 edu2

* Income
gen income2 = .

replace income2 = 1 if income == "Less than $10,000"
replace income2 = 2 if income == "$10,000 - $19,999"
replace income2 = 3 if income == "$20,000 - $29,999"
replace income2 = 4 if income == "$30,000 - $39,999"
replace income2 = 5 if income == "$40,000 - $49,999"
replace income2 = 6 if income == "$50,000 - $59,999"
replace income2 = 7 if income == "$60,000 - $69,999"
replace income2 = 8 if income == "$70,000 - $79,999"
replace income2 = 9 if income == "$80,000 - $89,999"
replace income2 = 10 if income == "$90,000 - $99,999"
replace income2 = 11 if income == "$100,000 - $149,999"
replace income2 = 12 if income == "More than $150,000"
replace income2 = 13 if income == "Prefer not to say"

label define income2 ///
    1 "Less than $10,000" ///
    2 "$10,000 - $19,999" ///
    3 "$20,000 - $29,999" ///
    4 "$30,000 - $39,999" ///
    5 "$40,000 - $49,999" ///
    6 "$50,000 - $59,999" ///
    7 "$60,000 - $69,999" ///
    8 "$70,000 - $79,999" ///
    9 "$80,000 - $89,999" ///
    10 "$90,000 - $99,999" ///
    11 "$100,000 - $149,999" ///
    12 "More than $150,000" ///
    13 "Prefer not to say"

label values income2 income2

save "workingdata.dta", replace
